﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.WinKStart.Abstract;
using WMSSoft.Lib.WinKStart.Extension;

namespace WMSSoft.Lib.WinKStart.ViewModel
{
    public class CEditContextMenuViewModel : CContextMenuViewModel
    {
        public CEditContextMenuViewModel()
        {
            base.ViewName = "Edit Context-Menu Item";
        }

        public override void LoadViewData(string ContextMenuItem)
        {
            base.LoadViewData(ContextMenuItem);

            ContextMenuItemKey = ContextMenuItem;

            if (cMenuConfigReader.ContextMenu.ContainsKey(ContextMenuItemKey) == true)
            {
                ViewData = cMenuConfigReader.ContextMenu[ContextMenuItemKey].Copy();
            }
        }

        protected override void ExecuteAddRegion()
        {
            base.ExecuteAddRegion();

        }

        protected override void ExecuteApplyData()
        {
            base.ExecuteApplyData();
            try
            {
                if (cMenuConfigReader.ContextMenu.ContainsKey(ContextMenuItemKey) == true)
                {
                    cMenuConfigReader.ContextMenu[ContextMenuItemKey].Assign(ViewData);
                }
                else throw new Exception("Unknown Context-Menu-Item '" + ContextMenuItemKey + "'!");
            }
            catch (Exception Ex)
            {
                CMessagelogging.AppendMessage("Can't Edit Context-Menu-Item!", Ex, EMessageTypes.Error);
            }
        }

        protected override void ExecuteDeleteRegion()
        {
            base.ExecuteDeleteRegion();
        }

        protected override void ExecuteDiscardData()
        {
            base.ExecuteDiscardData();
        }
    }
}
